<template>
	<view class="news-box">

		<view class="pic">
			<image :src="item.picurl" mode="aspectFill"></image>
		</view>
		<view class="text">
			<view class="title">
				{{item.title}}
			</view>
			<view class="info" v-if="!item.lookTime">
				<text>{{item.author}}</text>
				<text>{{item.hits}}浏览</text>
			</view>
			<view class="info" v-else>
				<text>浏览时间：{{item.lookTime}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "news-box",
		props: {
			item: {
				type: Object,
				// 若默认值是一个对象，则该对象需要返回一个函数
				default(){
					return {
						title: '默认标题',
						author: '默认作者名',
						hits: '99+',
						picUrl: '/static/images/nopic.jpg',
						lookTime: '2022-12-12 10:10:20'
					}
				}
			}
		},
		data() {
			return {

			};
		}
	}
</script>

<style lang="scss">
	.news-box {
		display: flex;

		.pic {
			width: 230rpx;
			height: 160rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.text {
			flex: 1; // 类选择器为text的元素 占满 父容器空闲的宽度
			// border: 2px solid red;
			padding-left: 20rpx;
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.title {
				color: #333;
				font-size: 36rpx;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.info {
				display: flex;
				font-size: 28rpx;
				color: #999;
				justify-content: space-between;
				text {
					padding-right: 20rpx;
				}
			}
		}
	}
</style>